package jp.co.systemi.asp.utils;

import java.util.logging.Logger;

import jp.co.systemi.asp.workflow.Main;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;

public class ConfirmDialog extends WebPage {
    @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(ConfirmDialog.class.getName());
    /** フィードバック */
    protected FeedbackPanel feedback = new FeedbackPanel("wi_feedback");
    public ConfirmDialog(final Main mainPage, final DModalWindow window, String message) {
        init(mainPage, window, message);
    }
    public void init(final Main mainPage, final DModalWindow window, String message) {
        feedback.setOutputMarkupId(true);
        add(feedback);

        Form<Object> form = new Form<Object>("wi_form");
        this.add(form);
        Label wi_message = new Label("wi_message", message);
        wi_message.setEscapeModelStrings(false);
        form.add(wi_message);
        form.add(new AjaxButton("wi_OK") {
            private static final long serialVersionUID = 5873629255088464587L;
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                PageParameters pars = new PageParameters();
                pars.add("confirm", "OK");
//                ((ICallback)mainPage).setResult(pars);
                window.setWindowClosedCallback(window.getOKActionCallback());
                window.close(target);
            }

        });
        form.add(new AjaxButton("wi_Cancel") {
            private static final long serialVersionUID = 5873629255088464587L;
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                window.setWindowClosedCallback(window.getCancelActionCallback());
                window.close(target);
            }
        });
    }
}
